// components/custom-navbar/custom-navbar.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        width: {
            type: String,
            value: 205
        },
        navTitle: {
            type: String,
            value: ''
        },
        title: {
            type: String,
            value: '默认标题'
        }, // 组件标题
        address: {
            type: String,
            value: '',
        },

        isShowTitle: {
            type: Boolean,
            value: true
        },
        isLeft: {
            type: Boolean,
            value: true
        },
        isRight: {
            type: Boolean,
            value: false
        },
        leftText: {
            type: String,
            value: '编辑'
        },
        leftColor: {
            type: String,
            value: '#262626'
        },
        rightText: {
            type: String,
            value: '编辑'
        },
        navLeftType: {
            type: String,
            value: 'arrow'
        },
        // 是否开启头部导航标签内容自定义slot插槽
        slotTile: {
            type: Boolean,
            value: true
        },
        textColor: {
            type: String,
            value: "#333333"
        },
        iconColor: {
            type: String,
            value: "#1A191E"
        },
        background: {
            type: String,
            value: "#FFF"
        }
    },
    options: {
        styleIsolation: 'shared'
    },

    /**
     * 组件的初始数据
     */
    data: {
        title: "",
        address: "",
        navLeft: null,
        slotTile: null,
        type: "",
    },

    /**
     * 组件数据字段监听器，用于监听 properties 和 data 的变化
     */
    observers: {
        "navLeftType": function (e) {
            this.setData({
                type: e
            })
            console.log('---', e)
        },
        "navTitle": function (e) {
            console.log(']]]', e)
        }
    },
    attached() {
        console.log('navTitle:', this.data.navTitle);
    },
    /**
     * 组件的方法列表
     */
    methods: {
        /**
         * 左侧内容点击回调函数方法
         */
        onClickLeft() {
            console.log('this.data.navTitle', this.data.navTitle)
            if (this.data.navTitle == '进货商城') {
                // if (!this.data.type) {
                //     wx.navigateBack({
                //         delta: 1
                //     })
                // }
            }else
            if (this.data.navTitle == '分类') {
                if (!this.data.type) {
                    wx.navigateBack({
                        delta: 1
                    })
                }
            } else if (this.data.navTitle == '购物车') {
                if (!this.data.type) {
                    wx.navigateBack({
                        delta: 1
                    })
                }
            } else {
                const pages = getCurrentPages();
                if (pages.length > 1) {
                    wx.navigateBack();
                } else {
                    wx.reLaunch({
                        url: '/pages/index/index'
                    });
                }
            }


            this.triggerEvent('onClickLeft')
        },


        /**
         * 右侧内容点击回调函数方法
         */
        onClickRight() {
            this.triggerEvent('onClickRight')
        },
        /**
         * 跳转搜索页
         */
        handleSearch() {
            wx.navigateTo({
                url: '/pages/search/index',
            })
        }
    }
})